/*   Copyright (C) 2008  Jeroen v. Schagen & Youri Lima
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace Engine.Rendering
{
    public class MeshInformation
    {
        private bool loaded;

        private Mesh mesh;
        private String name;
        private String file;
        private MeshType type;

        private Material[] materials;
        private Texture[] textures;

        public MeshInformation(String name, String file, MeshType t)
        {
            this.name = name;
            this.file = file;
            this.type = t;

            loaded = false;
        }

        public Mesh Mesh
        {
            get { return mesh; }
            set { mesh = value; }
        }

        public bool Loaded
        {
            get { return loaded; }
            set { loaded = value; }
        }

        public String Name
        {
            get { return name; }
            set { name = value; }
        }

        public String File
        {
            get { return file; }
            set { file = value; }
        }

        public Material[] Materials
        {
            get { return materials; }
            set { materials = value; }
        }

        public Texture[] Textures
        {
            get { return textures; }
            set { textures = value; }
        }

        public MeshInformation Clone()
        {
            try
            {
                MeshInformation clone = new MeshInformation(name, file, type);

                // Clone mesh
                clone.Mesh = mesh.Clone(MeshFlags.Managed, CustomVertex.PositionNormalColored.Format, mesh.Device);
                clone.Mesh.ComputeNormals();

                // Copy materials and textures
                clone.Materials = materials;
                clone.Textures = textures;

                return clone;
            }

            catch (Direct3DXException e)
            {
                throw e;
            }
        }
    }
}